/*
 * Copyright (c) 2010, Oracle. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of Oracle nor the names of its contributors
 *   may be used to endorse or promote products derived from this software without
 *   specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

/* 
 * Find.java
 *
 * Create on Mar 29, 2014 10:53:49 PM
 *
 * Copyright (c) 2014 Zhiyong's Design Studio.
 *
 * This software contains confidential proprietary information belonging
 * to Zhiyong's Design Studio. No part of this information may be used, reproduced, 
 * or stored without prior written consent of Zhiyong's Design Studio.
 *
 */
package com.zhiyongstudio.contactorbook;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class Find extends javax.swing.JFrame {
    private static Find _instance;
    private String findInput;
    private SIPNodesManagementFrame mainFrame;
    /** Creates new form Find */
    public Find() {
        initComponents();
    }

    public Find(SIPNodesManagementFrame mainFrame) {
        this.mainFrame = mainFrame;
        initComponents();
        this.setLocationRelativeTo(null);  
         this.setIconImage(new ImageIcon(getClass().getResource("/com/zhiyongstudio/contactorbook/icons/search.png")).getImage());
    } 
    
    public static Find getInstance(SIPNodesManagementFrame mainFrame){
        if(_instance == null){
            _instance = new Find(mainFrame);
        }
        
        return _instance;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel_Find = new javax.swing.JLabel();
        jTextField_FindInput = new javax.swing.JTextField();
        jButton_Find = new javax.swing.JButton();
        jButton_Cancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("com/zhiyongstudio/contactorbook/Bundle"); // NOI18N
        setTitle(bundle.getString("Find.title")); // NOI18N

        jLabel_Find.setText(bundle.getString("Find.jLabel_Find.text")); // NOI18N

        jButton_Find.setText(bundle.getString("Find.jButton_Find.text")); // NOI18N
        jButton_Find.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_FindActionPerformed(evt);
            }
        });

        jButton_Cancel.setText(bundle.getString("Find.jButton_Cancel.text")); // NOI18N
        jButton_Cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(0, 131, Short.MAX_VALUE)
                        .add(jButton_Cancel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton_Find, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(jLabel_Find)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextField_FindInput)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel_Find)
                    .add(jTextField_FindInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton_Cancel)
                    .add(jButton_Find))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_CancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CancelActionPerformed
         this.dispose();
    }//GEN-LAST:event_jButton_CancelActionPerformed

    private void jButton_FindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_FindActionPerformed
        if(!jTextField_FindInput.getText().isEmpty()){
            findInput = jTextField_FindInput.getText();
            mainFrame.findCallee(findInput);
            this.dispose();
        }else{
            JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("com/zhiyongstudio/contactorbook/Bundle").getString("FIND_USRNAME_EMPTY"));
        }
    }//GEN-LAST:event_jButton_FindActionPerformed

    public String getFindInput() {
        return findInput;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_Cancel;
    private javax.swing.JButton jButton_Find;
    private javax.swing.JLabel jLabel_Find;
    private javax.swing.JTextField jTextField_FindInput;
    // End of variables declaration//GEN-END:variables
    
}
